package HOT100;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 是阿秋啊
 * 电话号码的字母组合
 * @date 2022/11/24 14:17
 **/
public class Num17 {
    Map<String,String[]> map = new HashMap<String,String[]>(){
        {
            put("2",new String[]{"a","b","c"});
            put("3",new String[]{"d","e","f"});
            put("4",new String[]{"g","h","i"});
            put("5",new String[]{"j","k","l"});
            put("6",new String[]{"m","n","o"});
            put("7",new String[]{"p","q","r","s"});
            put("8",new String[]{"t","u","v"});
            put("9",new String[]{"w","x","y","z"});
        }
    };
    List<String> list = new ArrayList<>();
    public List<String> letterCombinations(String digits) {
        if (digits.length() < 1){
            return new ArrayList<>();
        }
        int i = 0;
        StringBuilder sb = new StringBuilder();
        fun(i,digits,sb);
        return list;
    }

    private void fun(int i, String digits,StringBuilder sb) {
        if (i >= digits.length()){
            list.add(sb.toString());
            return;
        }
        String[] tmp = map.get(digits.substring(i,i+1));
        for (String s : tmp) {
            sb.append(s);
            fun(i + 1, digits, sb);
            sb.deleteCharAt(i);
        }
    }

    public static void main(String[] args) {
        Num17 test = new Num17();
        List<String> list = test.letterCombinations("23");
        System.out.println(list.toString());
    }
}